package com.pruebas.andEngine;

import org.anddev.andengine.engine.handler.physics.PhysicsHandler;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

public class VillanoGris extends AnimatedSprite{
	private final PhysicsHandler mPhysicsHandler;
	private Float posicionActualX;
	private Float posicionActualY;
	private int camara_height = 0;
	private Boolean llegoPiso = false;
	static final int DESPLAZAMIENTO = 10;

	public VillanoGris(float pX, float pY, TiledTextureRegion pTiledTextureRegion) {
		super(pX, pY, pTiledTextureRegion);
		this.mPhysicsHandler = new PhysicsHandler(this);
	    this.registerUpdateHandler(this.mPhysicsHandler);
	}

	public boolean moveSprite(int valor){
		posicionActualX = this.getX();
		posicionActualY = this.getY();
			//le agregue 25 pixeles para que quede mas retirado del piso
			if(this.getY() + this.getHeight() + 25 <= camara_height && !llegoPiso){
				this.setPosition(posicionActualX - (DESPLAZAMIENTO + valor) , posicionActualY + 10); //this.getX() - 5
				return true;
			}else{
				llegoPiso = true;
	            this.setPosition(posicionActualX - (DESPLAZAMIENTO + valor), this.getY() - 10); //posicionActualX - 5
	            
	            if(posicionActualX <= -this.getWidth()){  //this.getX()
	            	llegoPiso = false;
	          	  this.stopAnimation();
	          	  return false;
	            }
	            else{
	            	llegoPiso = false;
	            	return true;
	            }
			}
	}
	
	
	public void setCamara_height(int camara_height) {
		this.camara_height = camara_height;
	}
	
	public int getCamara_height() {
		return camara_height;
	}
}
